import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class Converter {

    private static final Pattern LINE = Pattern.compile("(.+?)\\s*([+-]*)");

    public static void main(String[] args) throws IOException {
        if(args.length == 0) {
            System.out.println("Specify file to read!");
            return;
        }

        StringBuffer buffer = new StringBuffer();
        for(int i=0;i<args.length;i++) {
            String processResult = processFile(args[i]);
            if (processResult == null) {
                System.out.println("Error while processing file " + args[i]);
            } else {
                buffer.append(processResult).append("\n\n\n");
            }
        }

        FileWriter fileWriter = new FileWriter("output.txt");
        fileWriter.write(buffer.toString());        
        fileWriter.flush();
        fileWriter.close();

        System.out.println("All done!");
    }

    private static String processFile(String fileName) throws IOException {
        FileReader fileReader = new FileReader(fileName);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line;
        List<String> names = new ArrayList<String>();
        List<String> results = new ArrayList<String>();
        while((line = bufferedReader.readLine()) != null) {
            System.out.println("Processing line: " +line);
            Matcher matcher = LINE.matcher(line);
            if(matcher.matches()) {
                names.add(matcher.group(1));
                results.add(matcher.group(2));
            } else {
                System.out.println("Incorrect input");
                return null;
            }
        }

        StringBuffer buffer = new StringBuffer();
        for(int i=0;i<names.size();i++) {
            String result = results.get(i);
            for(int j=i+1;j<names.size();j++) {
                char res = result.charAt(j-i-1) == '+' ? '>' : '<';
                buffer.append(names.get(i)).append(" ").append(res).append(" ").
                       append(names.get(j)).append("\n");
            }
        }

        return buffer.toString();
    }
}
